package com.telrob.antlr.utils;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class NativeMethod {

	private Map<String,Boolean> map=null;
	
	public static void main(String[] args) {
		NativeMethod.getInstance();
	}
	
	private NativeMethod() {
		if(map==null) {
			map=new HashMap<String,Boolean>();
			FileInputStream fin=null;
			try {
				fin=new FileInputStream("native.lb");
				byte[]bb=new byte[1024*4];
				int len=0;
				ByteArrayOutputStream bout=new ByteArrayOutputStream();
				while((len=fin.read(bb))>0) {
					bout.write(bb,0,len);
				}
				bb=bout.toByteArray();
				bout.close();
				String str=new String(bb);
				String [] ss=str.split(",");
				for(String s:ss) {
					if(s!=null&&!"".equals(s)) {
						map.put(s, true);
					}
				}
				
			} catch (Exception e) {
			}finally {
				try {
					fin.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	public static NativeMethod getInstance() {
		return new NativeMethod();
	}
	
	public boolean isNative(String name) {
		Boolean is=map.get(name);
		if(is!=null&&is) {
			return true;
		}else {
			return false;
		}
	}
	
}
